package test.copy;

class Numbers{
    int num;
    public Numbers(int num){
        this.num = num;
    }
}
class Person implements Cloneable{
    int age;
    Numbers n;
    public Person(int age,Numbers n){
        this.age = age;
        this.n = n;
    }
    public Object clone() throws CloneNotSupportedException{
        return super.clone();
    }
}
public class CopyDemo {
    public static void main(String[] args) throws CloneNotSupportedException {
        Person p1 = new Person(18,new Numbers(10));
        Person p2 = (Person)p1.clone();
        System.out.println("修改之前p1与p2中age的值"+(p1.age == p2.age));
        p1.age = 15;
        System.out.println("修改之后p1与p2中age的值"+(p1.age == p2.age));
        System.out.println("修改之前p1与p2中number的值"+(p1.n.num == p2.n.num));
        p1.n.num=12;//修改P1内引用中的num的值
        System.out.println("修改之后p1与p2中number的值"+(p1.n.num == p2.n.num));

    }
}
